﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BloomsburyBanHang.DAO
{
    public class ChiTietHoaDonDAO
    {
        public ChiTietHoaDonDAO() { }

        public static List<CHI_TIET_HOA_DON> laydsHoaDonTheoMaHoaDon(int maHD)
        {
            NhaBanLeDataContext db = new NhaBanLeDataContext();
            List<CHI_TIET_HOA_DON> ds = null;
            var query = from hd in db.CHI_TIET_HOA_DONs
                        where hd.MaHoaDon == maHD
                        select hd;
            ds = query.ToList<CHI_TIET_HOA_DON>();
            return ds;
        }
        public static List<CHI_TIET_HOA_DON> taodsChiTietHoaDonTheoString(string dsSP, int maHoaDon)
        {
            NhaBanLeDataContext db = new NhaBanLeDataContext();
            List<CHI_TIET_HOA_DON> ds = new List<CHI_TIET_HOA_DON>();
          //  List<SAN_PHAM> dsSanPham = new List<SAN_PHAM>();
            string[] shoppingCartItem = dsSP.Split(',');
            //  string[] shoppingCartItem = shoppingcart.Split(',');
            for (int i = 1; i < shoppingCartItem.Count(); i++)
            {
                SAN_PHAM sp = new SAN_PHAM();
                sp = SanPhamDAO.TimSanPhamTheoMa(Convert.ToInt32(shoppingCartItem[i]));
                CHI_TIET_HOA_DON chitiet = new CHI_TIET_HOA_DON();
                //chitiet.HOA_DON.MaHoaDon = maHoaDon;
                chitiet.MaSanPham = sp.MaSanPham;
                chitiet.SoLuong = 1;
                chitiet.GiaLucMua = (double)sp.Gia;
              //  db.CHI_TIET_HOA_DONs.Attach(chitiet);
                ds.Add(chitiet);
            }
            //db.SubmitChanges();
            return ds;
        }
        
    }
}